Crate text_io [−] [src]
This crate allows one-liners to read from a terminal A minimal example to get an i32 from the command line is
#[macro_use] extern crate text_io; fn main() { let i: i32 = read!(); }
The read!()
macro will always read until the next ascii whitespace character
(\n
, \r
, \t
or space).
Any type that implements the FromStr
trait can be read with the read!
macro.
Advanced
Text parsing can be done similar to println!
by adding a format string
to the macro:
let i: i32 = read!("The answer: {}!");
This will read "The answer: "
, then an integer, then an exclamation mark. Any deviation from
the format string will result in a panic.
Note: only a single value can be read per read!
invocation.
Macros
read |
All text input is handled through this macro |
scan |
This macro allows to pass several variables so multiple values can be read |